package com.beyond.trace.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.beyond.trace.domain.FruitManage;
import com.beyond.trace.service.FruitManageService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * @ClassName: FruitManageController
 * @author: z越
 * @date: 2024/4/9  9:16
 * @description
 */
@RestController
@RequestMapping("/fruit/market")
@Api(tags = "水果行情管理")
@RequiredArgsConstructor
public class FruitManageController {
    private final FruitManageService fruitManageService;
    private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    @GetMapping("/list")
    @ApiOperation("查询当日行情数据")
    public AjaxResult list() throws ParseException {
        LambdaQueryWrapper<FruitManage> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(FruitManage::getTime,sdf.parse(DateUtils.getYesterday()));
        wrapper.orderByDesc(FruitManage::getCreateTime);
        return AjaxResult.success(this.fruitManageService.list(wrapper));
    }

    @GetMapping
    @ApiOperation("手动爬取水果行情网数据")
    public AjaxResult executeAdd(){
        this.fruitManageService.insertData();
        return AjaxResult.success();
    }
}
